feat: Refactor fstab parsing and add plugins for /etc/fstab and /proc/mounts#1613
feat: Refactor fstab parsing and add plugins for /etc/fstab and /proc/mounts#1613Yld2004 wants to merge 14 commits intofox-it:mainfrom
Conversation
|
@Yld2004 thank you for your contribution! As this is your first code contribution, please read the following Contributor License Agreement (CLA). If you agree with the CLA, please reply with the following information:
Contributor License Agreement
Contribution License AgreementThis Contribution License Agreement ("Agreement") governs your Contribution(s) (as defined below) and conveys certain license rights to Fox-IT B.V. ("Fox-IT") for your Contribution(s) to Fox-IT"s open source Dissect project. This Agreement covers any and all Contributions that you ("You" or "Your"), now or in the future, Submit (as defined below) to this project. This Agreement is between Fox-IT B.V. and You and takes effect when you click an “I Accept” button, check box presented with these terms, otherwise accept these terms or, if earlier, when You Submit a Contribution.
|
|
@DissectBot agree |
Schamper
left a comment
There was a problem hiding this comment.
Can you fix the linting errors?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1613 +/- ##
==========================================
+ Coverage 81.10% 81.14% +0.03%
==========================================
Files 401 403 +2
Lines 35175 35263 +88
==========================================
+ Hits 28529 28613 +84
- Misses 6646 6650 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Erik Schamper <1254028+Schamper@users.noreply.github.com>
Co-authored-by: Erik Schamper <1254028+Schamper@users.noreply.github.com> Co-authored-by: Yld2004 <77771298+Yld2004@users.noreply.github.com>
| fstab_data = fstab_file.readlines() | ||
|
|
||
| if len(entry_parts) != 6: | ||
| for line in fstab_data: |
There was a problem hiding this comment.
I meant more something like this:
| for line in fstab_data: | |
| with fstab.open("rt") as fh: | |
| for line in fh: |
There was a problem hiding this comment.
I wanted to do it but below it will sum up into 5 tabs Don't you think it will be too much tabs?
There was a problem hiding this comment.
It's fine. We have a 120 width line limit. Plenty of space :)
Description
Summary
This PR extracts the logic for parsing fstab-style entries into a reusable utility function and introduces two new plugins:
FstabPluginandMountPlugin. These changes allow for consistent extraction of mount information from both static configuration files and the volatile /proc environment.Key Changes
Logic Centralization:
Created
parse_fstab_entryindissect/target/plugins/os/unix/_os.py.Updated
parse_fstabto use this new centralized helper, improving handling of whitespace, comments, and field padding (defaults).New Plugins:
FstabPlugin:Located atetc.fstab, it yields records for entries found in/etc/fstab.MountPlugin:Located atlinux.proc.mounts, it iterates through all processes in/procand yields their respective mount points in the/proc/<pid>/mountsfile.Process Model Enhancement:
Added a
mounts()method to the Process class in the Linux proc plugin, allowing per-process mount inspection.Introduced FstabEntry dataclass for structured data handling within the proc module.
Testing:
Added comprehensive tests for the new plugins (
test_fstab.py,test_mounts.py).Updated conftest.py to include mock mount data for Linux process testing.